import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { HttpClient } from '@angular/common/http';
import { Base, LoginArg, LoginType } from '@configs/types';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class AccountService {

  private prefix = environment.baseUrl + '/hero/';
  constructor(private http: HttpClient) {}
  login(args: LoginArg): Observable<LoginType> {
    return this.http.post(this.prefix + 'login', args)
      .pipe(map((res: Base<LoginType>) => res.data));
  }
  account(): Observable<LoginType> {
    return this.http.get(this.prefix + 'account').pipe(map((res: Base<LoginType>) => res.data));
  }
  logout(): Observable<Base<void>> {
    return this.http.get<Base<void>>(this.prefix + 'logout');
  }
}
